/*
* @Author: dengjiayao
* @Date:   2017-08-29 14:08:25
* @Last Modified by:   dengjiayao
* @Last Modified time: 2017-09-20 14:14:03
*/
import Pages from '../../component/pages/pages.vue'
import { showMsg, getRecommendFollowList, deleteRecommendFollow, swapRecommendFollow } from '../../vuex/action'

export default {
  name: 'recommend-list',
  components: {
    'vue-pages': Pages
  },
  data() {
    return {
      list: [],
      filter: {
        type: 0
      }
    }
  },
  vuex: {
    getters: {
      fresh: state => state.portfolioListNeedFresh
    },
    actions: {
      xShowMsg: showMsg,
      xGetList: getRecommendFollowList,
      xDelete: deleteRecommendFollow,
      xSwap: swapRecommendFollow
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      let params = {}
      if (this.filter.type !== '') {
        params.type = this.filter.type
      }
      this.xGetList(params)
        .then((data) => {
          this.list = data.list
        })
        .catch((res) => {
          this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    },
    deleteItem(id) {
      this.xDelete({
        id: id
      })
        .catch((res) => {
          this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    },
    swap(id, id2) {
      this.xSwap({
        fromId: id,
        toId: id2
      })
        .catch((res) => {
          this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    }
  },
  watch: {
    fresh(val) {
      if (val) {
        this.getList({})
      }
    }
  }
}
